<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.*"%>
<%@ page import="message.*"%>
<%@ page import="social.*"%>
<%@ page import="QuizPackage.*" %>
<%@ page import="QuizPackage.*" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>QuizSite</title>
</head>
<%
	response.setHeader("Pragma", "no-cache"); //HTTP 1.0
	response.setHeader("Cache-Control",
			"no-cache, private, no-store, max-stale=0");
	response.setDateHeader("Expires", 0); //prevents caching at the proxy server
%>
<body>
<div id="header" style="background-color: #3B5998; color: white; font: Tahoma ">
<h1 style="margin-bottom: 0; text-align: center;">
<img src="Nuvola_apps_korganizer.png" alt="Smiley face" height="45" width="45" />
QuizSite
</h1> 
</div>

<h2>Please Log In</h2>

<h3>


<%
	if (session.getAttribute("username") != null) {
		response.sendRedirect("user-profile.jsp");
	}
	if (session.getAttribute("login") != null) {
		if (session.getAttribute("login").equals("false")) {
			out.println(String
					.format("Incorrect username or password. Please try again."));
		} else {
			//redirect to user profile page
		}
	}
%>
</h3>
<form action="LoginServlet" method="post">
<p>Username: <input type="text" name="username" /> </p>
<p>Password: <input type="password" name="password" /> <input type="submit"
	value="Login" /></p>
</form>

<a href="create-user.jsp">Create Account</a>

</body>

<p></p>
<div id="buffer"style="background-color: #3B5998; width: 100%; height: 10px; float: left">
</div>

<div id=Announcement
	style="background-color: #FFFFFF; min-height: 450px; width: 33%; float: left; color: #3B5998">
<%
	SocialDBC db = (SocialDBC) request.getServletContext()
			.getAttribute("database");
	out.println("<p></p><b style = \"font-size:130%\"> Announcement</a></b>");
	out.println("<img src=\"speaker_logo.jpg\" alt=\"Smiley face\" height=\"50\" width=\"50\" />");
	ArrayList<String> announcement = db.getAnnouncement();
	out.println("<ul>");
	for (int i = 0; i < announcement.size(); i++) {
		out.println("<li>" + announcement.get(i) + "</li>");
	}
	out.println("</ul>");
%>
</div>

<div id=PopularQuizzes
	style="background-color: #EEEEEE; min-height: 450px; width: 33%; float: left; color: #3B5998">
<p></p>
<p><b style="font-size: 130%"> Popular Quizzes   </b>
<img src="Diamond PV Logo.jpg" alt="Smiley face" height="50" width="50" >
</p>

<%
	QuizDBC qdb = (QuizDBC) request.getServletContext().getAttribute("quizDatabase");
	ArrayList<Integer> popularQuiz = qdb.getMostPopular();
	int temp = 15;
	if (temp > popularQuiz.size()) temp = popularQuiz.size();
	out.println("<ul>");
	for (int i = popularQuiz.size()-1; i>=popularQuiz.size()-temp; i--) {
		out.println(String
				.format("<li><a href=\"StartQuiz?quizid=%d\" > %s </a></li>",
						popularQuiz.get(i), qdb.getStringByID(popularQuiz.get(i), "name")));
	}
	out.println("</ul>");
%>
<p></p>
</div>

<div id=RecentQuizzes
	style="background-color: #FFFFFF; min-height: 450px; width: 33%; float: left; color: #3B5998">
<p></p>
<b style="font-size: 130%"> Recently Created Quizzes</b>
<img src="Treasure logo.jpg" alt="Smiley face" height="50" width="50" >"
<p></p>
<%
	ArrayList<Integer> quizList = qdb.getQuizList(false);
	if (quizList.size() == 0) {
		out.println("<p>No quizzes created.</p>");
	} else {
		out.println("<ul>");
		for (int i = 0; i < 10; i++) {
			if (i == quizList.size()) {
				break;
			} else {
				int quizID = quizList.get(i);
				String quizName = qdb.getStringByID(quizID, "name");
				out.println(String
						.format("<li><a href=\"StartQuiz?quizid=%d\" > %s </a></li>",
								quizID, quizName));
			}
		}
		out.println("</ul>");
	}
%>
</div>

<%
	response.setHeader("Pragma", "no-cache"); //HTTP 1.0
	response.setHeader("Cache-Control",
			"no-cache, private, no-store, max-stale=0");
	response.setDateHeader("Expires", 0); //prevents caching at the proxy server
%>
</html>